var prodownloadCheckedItems;
var data_data;
function getprodownloadData() {
    
    
    
	var startDate = $("#prodownloadStartDate").val();
	var endDate = $("#prodownloadEndDate").val();
    
    var markid = document.getElementById("prodownloadmark_id").options[document.getElementById("prodownloadmark_id").selectedIndex].value;
    
    var clientid = document.getElementById("prodownloadclient_id").options[document.getElementById("prodownloadclient_id").selectedIndex].value;
    
    var datetype = document.getElementById("prodownloaddate_type").options[document.getElementById("prodownloaddate_type").selectedIndex].value;
    
  
    
    
   

	$(".prodownloadChart").html("");
	if (startDate != "" && endDate != "")
	{
		var start = new Date();
		var end = new Date();

		//统计项
		var items = document.getElementsByName("prodownloadCheckbox");
		prodownloadCheckedItems = new Array();
		for(var i=0;i<items.length;i++) {
			if (items[i].checked)
			{
				prodownloadCheckedItems.push(items[i].value);
			}
		}

		if(prodownloadCheckedItems.length > 0) {


			jQuery('#body-wrapper').showLoading();
			start.setFullYear(startDate.substring(0,4), startDate.substring(5,7)-1, startDate.substring(8,10));
			end.setFullYear(endDate.substring(0,4), endDate.substring(5,7)-1 ,endDate.substring(8,10));

			days = parseInt((end - start)/1000/60/60/24)+1;

			var APIurl = "/client/prodownload?staDate="+startDate+"&pd="+days;
	        
            
            if (markid != ""){
				APIurl += "&mark_id="+markid;
            }
            
            if (clientid != ""){
				APIurl += "&client_id="+clientid;
            }
            
            if (datetype != ""){
				APIurl += "&date_type="+datetype;
            }
			

			
			$.ajax({
				type: "GET",
				url: APIurl,
				dataType : "json",
				jsonnp: "callback",
				success:function(data,textStatus){ loadprodownloadData(data)}
			});
            
            
            $.ajax({
  url: APIurl,
  type: "POST",
  data: "username="+login_username,
success: function(msg){
   //alert('ok');
}
});
            
		}
		else {
			alert("请选择至少一个统计项");
		}

	}
	else {
		alert("请选择时间区域");
	}
}


var prodownloadTabArr, prodownloadDetailArr, prodownloadSumArr, prodownloadDateArr, MainSubTitle;
function loadprodownloadData(data) {
    
    var markid = document.getElementById("prodownloadmark_id").options[document.getElementById("prodownloadmark_id").selectedIndex].value;
    
    var clientid = document.getElementById("prodownloadclient_id").options[document.getElementById("prodownloadclient_id").selectedIndex].value;
    
    var datetype = document.getElementById("prodownloaddate_type").options[document.getElementById("prodownloaddate_type").selectedIndex].value;
    
    data_data = data;
	var tab = "";
	var startDate = $("#prodownloadStartDate").val();
	var endDate = $("#prodownloadEndDate").val();
	MainSubTitle = startDate.replace(/\//g, "-") + " 至 " + endDate.replace(/\//g, "-");
	jQuery('#body-wrapper').hideLoading();	
    
    
    


	prodownloadTabArr = new Array();
	prodownloadDetailArr = new Array();
	prodownloadSumArr = new Array();
	prodownloadDateArr = new Array();
    
    
    if(data['zongji'] != "0"){

			
            
         
        changeChartType('prodownload','Pie');
        
        
        
        //生成表格
        genTop10Tableprodownload("prodownloadTable", valueFullNameArr(prodownloadCheckedItems), prodownloadTabArr, data['All']['table'], prodownloadCheckedItems,data['All']['rtable'],data['All']['atable']);
        
        //生成线图
        //genSummaryLineChart_prodownload("prodownloadPie","渠道下载量排名趋势图",data['All']['xianx'],data['All']['xiany'],data['All']['xianm']);
        
        
        //生成线形图
            genSelLineChart_prodownload(markid,"prodownloadPie",data['All']['xiany'],data['All']['xianx'],data['All']['xianm'],datetype);

        
    }
    else{
        
    alert("选择的时间区间内无数据");
    
    }
	
}




